import os
import sys


def print_data(absPath, encode):
    file = open(file=absPath, mode='r', encoding=encode)
    data = file.read()
    file.close()
    print(data)


def print_file():
    # print(sys.argv)
    if len(sys.argv) >= 2:
        pathName = sys.argv[1]
        if len(sys.argv) >= 3:
            encode = sys.argv[2]
        else:
            encode = 'UTF-8'
        absPath = os.path.join(os.getcwd(), pathName)
        if os.path.exists(absPath):
            print_data(absPath, encode)
        elif os.path.exists(pathName):
            print_data(pathName, encode)
        else:
            print(pathName + ':文件不存在！')
    else:
        print('没有输入参数！')


# 按间距中的绿色按钮以运行脚本。
if __name__ == '__main__':
    print_file()
